package com.ld.security.shop.im.util;

import com.ld.security.common.core.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessageSendingOperations;
import org.springframework.stereotype.Component;


@Component
public class ImUtil {


    private static SimpMessageSendingOperations simpMessageSendingOperations;


    /**
     * 向指定用户发送消息
     * @param key
     * @param val
     */
    public static void sendMsg(String key,Object val){
        simpMessageSendingOperations.convertAndSend(key,JsonUtil.toJson(val));
    }

    public static SimpMessageSendingOperations getSimpMessageSendingOperations() {
        return simpMessageSendingOperations;
    }

    @Autowired
    public void setSimpMessageSendingOperations(SimpMessageSendingOperations simpMessageSendingOperations) {
        ImUtil.simpMessageSendingOperations = simpMessageSendingOperations;
    }
}
